package com.luli.service.impl;

import com.luli.Utils.PojoUtil;
import com.luli.dao.PhotoDao;
import com.luli.entity.photo.Paths;
import com.luli.entity.photo.Photo;
import com.luli.service.PhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 陆离
 * 2022/5/7 10:08:11
 */
@Service
public class PhotoServiceImpl implements PhotoService {
    @Autowired
    private PhotoDao photoDao;

    /**
     * 测试文件上传
     */
    @Autowired
    private Paths paths;

    @Override
    public Integer addPhoto(Photo photoTest) throws IOException {
        //上传到指定目录
        HashMap<String, Object> stringObjectHashMap = PojoUtil.uploadFile(photoTest.getUpload(), paths.getReportUploadPath());
        //存路径
        photoTest.setSfile(String.valueOf(stringObjectHashMap.get("uploadPath")));
        photoTest.setName(photoTest.getUpload().getOriginalFilename());
        return photoDao.addPhoto(photoTest);
    }

    @Override
    public Integer deletePhoto(String photoPath, String photoId) {
        Map<String, Object> map = PojoUtil.deleteFile(photoPath);
        Integer integer = photoDao.deletePhoto(photoId);
        return integer;
    }
}
